package com.briup.springboot_web.config;

import com.briup.springboot_web.web.interceptor.MyInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置springMVC相关的代码
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired //从ioc中获取拦截器对象
    private MyInterceptor myInterceptor;
    //添加拦截器


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //通过注册对象添加拦截器,设置拦截规则
        registry.addInterceptor(myInterceptor)
                .addPathPatterns("/**");//表示拦截所有请求url

    }
}
